package top.zlhy7.module.work.vo;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

import java.math.BigDecimal;

import static top.zlhy7.base.constant.Constants.ONE_HUNDRED;

/**
 * @author renyong
 * @date 2024/9/30 01:08
 * @description 工单统计1：查询某月每天工单总数，超期率
 */
@Data
public class WorkOrderStatistics1Vo {
    /**
     * 统计日期
     */
    private String statisticsDate;
    /**
     * 总工单数
     */
    private Integer totalOrderQuantity;
    /**
     * 超期工单数
     */
    private Integer overdueOrderQuantity;
    /**
     * 超期率=(超期工单数/总工单数)*100%
     */
    private BigDecimal overdueRate;
    /**
     * 超期率 百分数形式
     */
    private String overdueRatePerCent;
    //region 筛选条件
    /**
     * 统计月份，格式：yyyy-MM
     */
    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    private String yearMonth;
    //endregion

    public WorkOrderStatistics1Vo() {
        this.totalOrderQuantity = 0;
        this.overdueOrderQuantity = 0;
        this.setOverdueRate(BigDecimal.ZERO);
    }
    public WorkOrderStatistics1Vo(String statisticsDate){
        this();
        this.statisticsDate = statisticsDate;
    }
    public void setOverdueRate(BigDecimal overdueRate){
        this.overdueRate = overdueRate;
        if (overdueRate==null) {
            this.overdueRatePerCent = "0%";
            return;
        }
        this.overdueRatePerCent = overdueRate.multiply(ONE_HUNDRED).setScale(2, BigDecimal.ROUND_HALF_UP).toString() + "%";
    }
}
